<!DOCTYPE html>
<html>
<head>
<title>Template</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css"/>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-icon.css"/>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-revise.css"/>
<script type="text/javascript" src="../ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../ext/ext-all.js"></script>
<script type="text/javascript" src="../ext/ext-revise.js"></script>
<script type="text/javascript" src="../ext/src/locale/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
</head>

<body>
<script type="text/javascript">
var detailWinForm = new Ext.form.FormPanel({
    baseCls: "x-plain",
    layout: "table",
    layoutConfig: {
        columns: 2
    },
    defaults: {
        baseCls: "x-plain",
        xtype: "panel",
        labelAlign: "right",
        layout: "form",
        labelWidth: 70,
        labelSeparator: ":&nbsp;&nbsp;"
    },
    items: [{
    	style: "margin-top:4px",
        items: [{
            xtype: "textfield",
            fieldLabel: "产品名称",
            name: "productName"
        }]
    }, {
		style: "margin-left:4px",
        items: [{
            xtype: "button",
			name: "search",
            text: "检索",
            iconCls: "Search"
        }]
    }]
});
var detailWinGridCM = new Ext.grid.CheckboxSelectionModel({
    handleMouseDown: Ext.emptyFn
});
var detailWinGrid = new Ext.grid.GridPanel({
    height: 260,
	sm: detailWinGridCM,
    cm: new Ext.grid.ColumnModel([
		detailWinGridCM,
        {header: "产品编号", dataIndex: "productNo"},
        {header: "产品名称", dataIndex: "productName"},
        {header: "产品品牌", dataIndex: "productBrand"},
        {header: "产品型号", dataIndex: "productModel"},
        {header: "产品单价", dataIndex: "productPrice"}
    ]),
    loadMask: {msg: "数据加载中..."},
    store: new Ext.data.SimpleStore({
        fields: ["productNo", "productName", "productBrand", "productModel", "productPrice"],
        data: [
			["A1", "B1", "C1", "D1", "E1"],
			["A2", "B2", "C2", "D2", "E2"],
			["A3", "B3", "C3", "D3", "E3"]
		]
    }),
	bbar: new Ext.PagingToolbar({
		store: [[]],
		pageSize: 20,
		displayInfo: true,
		displayMsg: "显示第{0}条到{1}条记录  共{2}条",
		emptyMsg: "没有记录"
	})
});
var detailWin = new Ext.Window({
	title: "采购产品选择",
	width: 660,
	modal: true,
	resizable: false,
	draggable: false,
    closeAction: "hide",
    buttonAlign: "right",
    defaults: {
        baseCls: "x-plain"
    },
    items: [detailWinForm, detailWinGrid],
    buttons: [{
		text: "确定"
	}, {
        text: "关闭", handler: function() {detailWin.hide();}
    }],
    listeners: {
        "hide": function(win) {
            win.buttons[0].handler = function() {};
        }
    }
});

function popupDetailWin(callback, params) {
    params = params || {};
	
    detailWin.buttons[0].handler = function() {
        var sm = detailWinGrid.getSelectionModel();
        if (sm.getCount() != 1) {
            Ext.Msg.alert("提示框", "请选择一个采购产品！");
            return;
        }
        
        var record = sm.getSelected();
        if (callback && typeof callback == "function") {
            callback(record);
        }
        detailWin.hide();
    }
    detailWinForm.find("name", "search")[0].handler = function() {
        Ext.apply(detailWinGrid.getStore().baseParams, detailWinForm.getForm().getValues());
        detailWinGrid.getStore().load({params: {start: 0, limit: 20}});
    }
	
	detailWin.show();
	//detailWinGrid.getStore().removeAll();
	//detailWinGrid.getStore().baseParams = {};
	//Ext.apply(detailWinGrid.getStore().baseParams, params);
    //detailWinGrid.getStore().load({params: {start: 0, limit: 20}});
}

var form = new Ext.form.FormPanel({
	renderTo: Ext.getBody(),
	frame: true,
	items: [{
		xtype: "combo",
		fieldLabel: "Detail Combo",
		name: "detailCombo",
		store: [[]],
		mode: "local",
		editable: false,
		valueField: "value",
		displayField: "text",
		listeners: {
			"expand": function(combo) {
				combo.collapse();
			}
		}
	}]
});

Ext.onReady(function() {
	jQuery("[name='detailCombo']").parent().children("img").click(function() {
		popupDetailWin(function(record) {
			var detail = form.find("name", "detailCombo")[0];
			var tempRecord = new Ext.data.Record({
				value: record.data["productNo"],
				text: record.data["productName"]
			});
			detail.store.removeAll();
			detail.store.add(tempRecord);
			detail.setValue(record.data["productNo"]);
		})
	});
});
</script>
</body>
</html>
